package com.hsh.vo.dto.convert;

import com.hsh.entity.SysDictData;
import com.hsh.vo.dto.result.TreeSelect;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * mapstruct 对象转换
 * </p>
 *
 * @author huangsihai
 * @date 8/28/2021
 */
@Mapper
//@Mapper(componentModel = "spring")
public interface MapStructConvertVo {

    MapStructConvertVo INSTANCE = Mappers.getMapper(MapStructConvertVo.class);

    @Mappings({
            @Mapping(source = "id", target = "userId"),
            @Mapping(source = "name", target = "userName"),
            @Mapping(source = "money", target = "money"),
            @Mapping(source = "delFlag", target = "whetherDel", qualifiedByName = {"intConvertBol"}),
    })
    UsersVo usersConvertToUsersVo(Users param);

    @Named("intConvertBol")
    default Boolean intConvertBol(Integer flag) {
        if (Objects.isNull(flag)) {
            return false;
        }
        return flag == 1;
    }

    @Mappings({
            @Mapping(source = "dictValue", target = "value")
    })
    List<TreeSelect> getTreeList(List<SysDictData> param);
}
